package cn.schoolwow.flow.monitor.test.module.testcase.business;

import cn.schoolwow.flow.monitor.domain.TestCaseFlow;
import cn.schoolwow.flow.monitor.test.entity.User;
import cn.schoolwow.quickdao.domain.DAO;
import cn.schoolwow.quickflow.domain.FlowContext;
import org.springframework.context.ApplicationContext;

public class UserLoginTestCaseFlow implements TestCaseFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        String username = (String) flowContext.getData("username", "flowMonitor");
        String password = (String) flowContext.getData("password", "123456");
        ApplicationContext applicationContext = flowContext.checkInstanceData(ApplicationContext.class);
        DAO starterDAO = applicationContext.getBean("starterDAO", DAO.class);

        long count = starterDAO.query(User.class)
                .addQuery("username", username)
                .addQuery("password", password)
                .execute()
                .count();
        if(count>=0){
            System.out.println("登录成功");
        }else{
            System.out.println("登录失败");
        }
    }

    @Override
    public String name() {
        return "用户登录";
    }

}
